<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"/>
    <title>父子组件双向绑定</title>
    <style>
        [v-cloak]{
            display:none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak></div>
<script src="js/vue.js"></script>
<script>
    let InputComponent={
        template:`
          <div>
            <input type="text" v-model="currentValue">
          </div>
        `,
        data(){
            return {

            }
        },
        props:{
            value:{
                type:String
            }
        },
        computed:{
          currentValue:{
              get(){
                  console.log("get value:" + this.value)
                  return this.value;
              },

              set(val){
                  console.log("set value:" + val)
                  this.$emit("input",val);
              }
          }
        },
        methods:{

        }
    };
    //父组件
    let ParentComponent={
        template:`
           <div>
                <InputComponent v-model="value"></InputComponent>{{value}}
           </div>
        `,
        data(){
            return {
                value:""
            }
        },
        created(){

        },
        components:{
            InputComponent
        }
    };
    //入口组件
    let App={
      template:`
        <div>
            <ParentComponent></ParentComponent>
        </div>
      `,
        //局部组件注册方式
        components: {
            ParentComponent
        }
    };
    new Vue({
        el:"#app",
        template:`
                <App></App>
        `,
        components:{
            App
        }
    })
</script>
</body>
</html>
